package ThreadAndLambda.Lambda;
/*
    使用runnable接口的方式实现多线程程序
*/
public class RunnableTest {
    public static void main(String[] args) {
        //创建runnable接口的实现类对象
        RunnableImp runnableImp=new RunnableImp();
        //创建thread类对象，构造方法传递runnable接口的实现类
        Thread thread=new Thread(runnableImp);
        //调用start开启线程，执行run
        thread.start();

        //简化代码，使用匿名内部类，实现多线程
        Runnable  runnable=new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
            }
        };
        new Thread(runnable).start();

        //继续简化
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
            }
        }).start();
    }

}
